package org.vidi.jms.topic;

import org.vidi.jms.common.ConnectionUtils;
import org.vidi.jms.common.Constants;

import javax.jms.*;

/**
 * @author vidi
 */
public class SimpleTopicReceiver {
    public static void main(String[] args) throws JMSException {
        TopicConnectionFactory factory = (TopicConnectionFactory) ConnectionUtils.getConnectionFactory();
        TopicConnection connection = factory.createTopicConnection();
        connection.start();

        TopicSession session = connection.createTopicSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Topic topic1 = session.createTopic(Constants.SIMPLE_TOPIC_NAME_1);
        Topic topic2 = session.createTopic(Constants.SIMPLE_TOPIC_NAME_2);
        TopicSubscriber subscriber1 = session.createSubscriber(topic1);
        TopicSubscriber subscriber2 = session.createSubscriber(topic2);

        TextMessage message1 = (TextMessage) subscriber1.receive();
        TextMessage message2 = (TextMessage) subscriber2.receive();

        session.close();
        connection.close();

        System.out.println(message1.getText());
        System.out.println(message2.getText());
    }
}
